package ar.com.softtek.departments.validator;

import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import ar.com.softtek.departments.model.Department;

@Component
public class DepartmentValidator implements Validator {
	public boolean supports(Class<?> clazz) {
		return (clazz.isAssignableFrom(Department.class));
	}

	public void validate(Object command, Errors errors) {
		Department department = (Department) command;
		if (!StringUtils.hasText(department.getName())) {
			errors.rejectValue("name", "error.required.name",
					"Name is required");
		}
	}
}
